package org.jzb.test.route;

import io.quarkus.security.Authenticated;
import io.quarkus.security.identity.SecurityIdentity;
import io.quarkus.vertx.web.Param;
import io.quarkus.vertx.web.Route;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;

import javax.inject.Inject;
import javax.ws.rs.core.MediaType;

@Authenticated
public class ApiRoute {
  @Inject SecurityIdentity identity;

  @Route(path = "/api/services/:service/actions/:action", produces = MediaType.APPLICATION_JSON)
  public void route(
      RoutingContext rc, @Param("service") String service, @Param("action") String action) {
    final var principal = identity.getPrincipal();
    final var jsonObject =
        new JsonObject()
            .put("principal", principal.getName())
            .put("service", service)
            .put("action", action);
    rc.response().end(jsonObject.toBuffer());
  }
}
